<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iCittys會員中心 - 登錄</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/global.css" rel="stylesheet" type="text/css" />
</head>
<body>

<!-- 头部 -->
<div class="top">
	<div class="l">
		iCittys 會員中心
	</div>
	<div class="top_ad r">

	</div>
</div>

<!-- 导航 -->
<div class="menu">
	<span class="l">iCittys登錄頁面!</span>
	<span class="r">
		<a href="login.html">登錄</a>
		<a href="reg.html">註冊</a>		
	</span>
</div>
<div class="bottombg"></div>

<!-- 注册信息 -->
<div class="reg">

<form method="post" onsubmit="return disposal();" name="loginform">

	<div class="div_form">
		<div class="div1 l">帳號：</div>
		<div class="div2 l"><input class="div2_input" name="username" type="text" id="username" /></div>
		<div class="div3 l">請用使用者名稱或Email來登錄 </div>
	</div>

	<div class="div_form">
		<div class="div1 l">密碼：</div>
		<div class="div2 l"><input class="div2_input" name="password" type="password" id="password" /></div>
		<div class="div3 l">6～20個合法字符组成</div>
	</div>

	<div class="div_form">
		<div class="div1 l">&nbsp;</div>
		<div class="div2 l">
			<label><input class="div2_submit" type="submit" id="Submit" name="sub" value="登錄" /></label>
			<label><input class="div2_submit" type="reset" name="Submit" value="重 置" /></label>	
		</div>
		<div class="div3 l"></div>
	</div>

</form>

</div>

<div class="footer">
	<p>Powerd By APP-SSO</p>
	<p>技術支援：support@icittys.com </p>
</div>
<script type="text/javascript" src="http://hot.icittys.com/js/phprpc_client.js"></script>

<script type="text/javascript">
  <!--
	
	var APP_SSO_URL = 'http://app-sso.appspot.com/';
	var MAX_Retry = 100;
	var Retry_count = 0;
	var http_response_code = {
		HTTP_RESPONSE_SIGN_NO:1,
		HTTP_RESPONSE_EMAIL_NO:2,
		HTTP_RESPONSE_EMAIL_OK:3,
		HTTP_RESPONSE_LOGIN_OK:4,
		HTTP_RESPONSE_DB_ERROR:5,
		HTTP_RESPONSE_LOGOUT_OK:6,
		HTTP_RESPONSE_DELETE_OK:7,
		HTTP_RESPONSE_DELETE_NO:8,
		HTTP_RESPONSE_UPDATE_OK:9,
		HTTP_RESPONSE_REGISTER_OK:10,
		HTTP_RESPONSE_VALIDATE_NO:11,
		HTTP_RESPONSE_VALIDATE_OK:12,
		HTTP_RESPONSE_USERNAME_NO:13,
		HTTP_RESPONSE_USERNAME_OK:14,
		HTTP_RESPONSE_PASSWORD_NO:15,
		HTTP_RESPONSE_EMAIL_EXISTS:16,
		HTTP_RESPONSE_VARIABLE_ERROR:17,
		HTTP_RESPONSE_USERNAME_EXISTS:18,
		HTTP_RESPONSE_EMAIL_NOT_EXISTS:19,
		HTTP_RESPONSE_USERNAME_NOT_EXISTS:20
	};
	var login_ok_array = [];
	
	function is_password(str)
	{
		var i, c;
		if(str.length < 5 || str.length > 19)
		{
			return false;
		}
		for(i=0; i < str.length; i++)
		{
			c = str.charAt(i);
			if( (c < "0" || c > "9") && (c < "a" || c > "z" ) && (c < "A" || c > "Z" ))
			{
				return false;
			}
		}
		return true;
	}


	function isEmail(strEmail) 
	{
		if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		{
			return true;
		}

		return false;
	}

	function is_username(username)
	{
		var patrn = /^[a-zA-Z0-9]{3,20}$/; 


		if(!patrn.exec(username))
		{
			return false;
		}

		return true;
	}

	function check_responce_code(info)
	{
		var code = info['code'];
		switch (code)
		{
			case http_response_code.HTTP_RESPONSE_USERNAME_NOT_EXISTS :
				alert("用戶名不存在");
				break;
			case http_response_code.HTTP_RESPONSE_EMAIL_NOT_EXISTS :
				alert("電子郵件不存在");
				break;
			case http_response_code.HTTP_RESPONSE_PASSWORD_NO :
				alert("密碼驗證失敗");
				break;
			case http_response_code.HTTP_RESPONSE_VALIDATE_NO :
				alert("驗證碼錯誤，請先至信箱中收取認證碼信件，並按下認證連結");
				break;
			case http_response_code.HTTP_RESPONSE_LOGIN_OK :
				login2_many_server(info['lists']);
				break;
			default:
				alert("不知名錯誤");
		}
		frm = document.forms["loginform"];
		frm.elements["sub"].disabled = false;
		frm.elements["sub"].value    = "登錄";
	}
	function login(url, info){
		var rpc = new PHPRPC_Client(url, ['login']);
		rpc.login(info, function(result){
			if(result == 4)login_ok_array[login_ok_array.length] = result;
		});
	}
	function check_login(){
			if(login_ok_array.length >= sites_nums){
				alert("登錄成功");
				var myregexp = /\?done=([^&]+)/;
				var match = myregexp.exec(location.href);
				if (match != null) {
					window.location.href = decodeURIComponent(match[1]);
				} else {
					window.location.href = "http://hot.icittys.com/member/";
				}
				frm = document.forms["loginform"];
				frm.elements["sub"].disabled = false;
				frm.elements["sub"].value    = "登錄";
			}else{
				Retry_count++;
				if(Retry_count<MAX_Retry){
					setTimeout(check_login,100);
				}else{
					alert('註冊超時，請重新登入');
					frm = document.forms["loginform"];
					frm.elements["sub"].disabled = false;
					frm.elements["sub"].value    = "登錄";
				}
			}
	}
	function login2_many_server(lists){
		sites_nums = lists.length;
		for(var i in lists){
			var url = lists[i]['url'];
			var info = lists[i];
			delete info['url'];
			//console.dir(info);
			login(url, info);
		}
		setTimeout(check_login,100);
	}
	function disposal()
	{
		var url, frm;
		frm  = document.forms["loginform"];
		
		if(frm.elements["username"].value == '')
		{
			alert("請填寫帳號");
			return false;
		}
		if(!is_password(frm.elements["password"].value))
		{
			alert("請填寫密碼");
			return false;
		}
		
		var rpc = new PHPRPC_Client(APP_SSO_URL, ['login']);
		rpc.login(frm.elements["username"].value, frm.elements["password"].value,function(result){
			check_responce_code(result);
		});
		frm.elements["sub"].disabled = true;
		frm.elements["sub"].value    = "正在登錄中,請稍後....";
		return false;
	}
  //-->
  </script>
</body>
</html>